<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/incube-app.tld" prefix="app" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ page import = "org.apache.struts.Globals,java.util.*,org.fiel.domain.Informacion,org.fiel.login.FielPrincipal"%>
<%!
	int id = 1;
	int iteracion = 1;
	int cantpordiv = 0; // Se inicializa en initVars

	public String initVars(String cant){
		id = 1;
		cantpordiv = Integer.parseInt(cant);
		iteracion = 0;
		return "";
	}
	
	public String getNextID(){
		return Integer.toString(id++);
	}
	public String getStyle(){
		if((id - 1) > 1)
			return "style=\"display:none\"";
		return "";
	}
	public String incrementarIterador(){
		iteracion += 1;
		return "";
	}

	public String getHeaderDIV(){
		if( (iteracion % cantpordiv) == 0){
			return "<div id=\"p" + getNextID()+ "\" " + getStyle() + ">";
		}
		return "";
	}
		
	public String getFooterDIV(){
		if(((iteracion + 1) % cantpordiv) == 0){
				return "</div>";
		}
		return "";
	}
%>
<%
	FielPrincipal fielPrincipal = (FielPrincipal) request.getSession().getAttribute("userPrincipal");
	String rol = "0";
	if(fielPrincipal != null ){
		List ls = fielPrincipal.getRoles();
		for (Iterator iter = ls.iterator(); iter.hasNext();) {
			rol += (String) iter.next();
		}
	}
	
	ArrayList al = (ArrayList) session.getAttribute("libros");
	Informacion inf = null;
	for(int i=0;i<al.size();i++){
		inf = (Informacion) al.get(i);
		if(inf.getNivel().equals("1") && rol.indexOf("1") == -1){
			inf.setNameFile(null);
		}
		if((inf.getNameFileE() == null) || (inf.getNameFileE().equals(""))){
			inf.setNameFileE(inf.getNameFile());
		}
		if((inf.getTituloE() == null) || (inf.getTituloE().equals(""))){
			inf.setTituloE(inf.getTitulo());
		}
		if((inf.getAbstractE() == null) || (inf.getAbstractE().equals(""))){
			inf.setAbstractE(inf.getAbstract());
		}
	}
	session.setAttribute("libros",al);
%>
<%=initVars("2")%>
<bean:define id="locale" name="<%=Globals.LOCALE_KEY%>" type="java.util.Locale"/>
<script language="javascript">showLabel('publicacionesLibros')</script>
<table border="0" cellpadding="5" cellspacing="0" height="100%" style="font-family:arial;font-size:8pt" width="100%">
<tr>
	<td valign="top">
		<logic:iterate id="info" name="libros" type="org.fiel.domain.Informacion">
			<bean:define id="imagen" name="info" property="imagen" />
			<%=getHeaderDIV()%>
			<table border="0" width="100%">
				<tr>
					<td valign="top" width="100px"> 
						<logic:equal name="locale" property="language" value="es">
							<logic:notEmpty name="info" property="nameFile">
								<a class="celeste" href="/publicaciones/Libros/<%=info.getNameFile() %>" target="_blank">
							</logic:notEmpty>
							<logic:notEmpty name="info" property="imagen">
								<img  border="0" src="/publicaciones/Libros/<%=imagen%>">
							</logic:notEmpty>
							<logic:empty name="info" property="imagen">
								<img border="0" src="/publicaciones/Libros/blank.jpg">
							</logic:empty>
							<logic:notEmpty name="info" property="nameFile">
								</a>
							</logic:notEmpty>
						</logic:equal>
						<logic:equal name="locale" property="language" value="en">
							<logic:notEmpty name="info" property="nameFileE">
								<a class="celeste" href="/publicaciones/Libros/<%=info.getNameFileE() %>" target="_blank">
							</logic:notEmpty>
							<logic:notEmpty name="info" property="imagen">
								<img  border="0" src="/publicaciones/Libros/<%=imagen%>">
							</logic:notEmpty>
							<logic:empty name="info" property="imagen">
								<img border="0" src="/publicaciones/Libros/blank.jpg">
							</logic:empty>
							<logic:notEmpty name="info" property="nameFileE">
								</a>
							</logic:notEmpty>
						</logic:equal>
					</td>
					<td valign="top" style="text-align:justify">
						<logic:equal name="locale" property="language" value="es">
							<logic:notEmpty name="info" property="nameFile">
								<a class="celeste" href="/publicaciones/Libros/<%=info.getNameFile() %>" target="_blank">
									<bean:write name="info" property="titulo"/>
								</a>
							</logic:notEmpty>
							<logic:empty name="info" property="nameFile">
								<span class="celeste"><bean:write name="info" property="titulo"/></span>
							</logic:empty>
							<br>
							<span style="color:#000000;font-size:8pt;font-weight:normal" >
								<bean:write name="info" property="abstract" />
							</span>
							<br>
							<span style="color:#333399;font-size:8pt;font-weight:bold">
								<bean:write name="info" property="costo" />
							<span>
						</logic:equal>
						<logic:equal name="locale" property="language" value="en">
							<logic:notEmpty name="info" property="nameFileE">
								<a class="celeste" href="/publicaciones/Libros/<%=info.getNameFileE() %>" target="_blank">
									<bean:write name="info" property="tituloE"/>
								</a>
							</logic:notEmpty>
							<logic:empty name="info" property="nameFileE">
								<span class="celeste"><bean:write name="info" property="tituloE"/></span>
							</logic:empty>
							<br>
							<span style="color:#000000;font-size:8pt;font-weight:normal" >
								<bean:write name="info" property="abstract" />
							</span>
							<br>
							<span style="color:#333399;font-size:8pt;font-weight:bold">
								<bean:write name="info" property="costo" />
							<span>
						</logic:equal>
					</td>
				</tr>
			</table>
			<br>		 
			<%=getFooterDIV()%>
			<%=incrementarIterador()%>
		</logic:iterate>
		<%
			if ((iteracion % cantpordiv) != 0){
		%>
			</div>
		<%	
			}
		%>		
	</td>
	<td width="5%" valign="bottom">
		<a href="javascript:scrollUp()"><img border="0" src="images/scrollup.gif"></a>
		<a href="javascript:scrollDown()"><img border="0" src="images/scrolldown.gif"></a>
	</td>
</tr>
</table>
